﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace Util.Machlearn
{
    /// <summary>
    /// An real-valued observation. 
    /// </summary>
    public class OVector:ICloneable, ISerializable
    {
        private double[] _values;

        public double[] Values
        {
            get { return _values; }
        }


        /** Constructs a new observation for a given feature-vector. */
        public OVector(double[] values) 
        {
            this._values = values;
        }

        public OVector(float[] values)
        {
            this._values = new double[values.Length];
            for (int i = 0; i < _values.Length; i++)
                _values[i] = values[i];

        }

        /** Creates a one-dimensional instance of this class. */
        public OVector(double value) 
            :this(new double[]{value})
        {
            
        }

        /** Returns the dimension of this observation. */
        public int dimension() 
        {
            return _values.Length;
        }


        override
        public Boolean Equals(Object obj) 
        {
            return obj is OVector && 
                _values.Equals(((OVector) obj)._values);

        }

        override
        public String ToString() 
        {
            StringBuilder strBuilder = new StringBuilder();
            for (int i = 0; i < _values.Length; i++)
            {
                //strBuilder.AppendFormat("{0};{1};;\n", i, _values[i]);
                strBuilder.AppendFormat("{0};;", _values[i]);
            }
            return strBuilder.ToString();
        }

        object ICloneable.Clone()
        {
            return MemberwiseClone();
        }

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            throw new NotImplementedException();
        }
    }
}
